package com.littleken.foodieApi.controller;

import com.littleken.foodieCommon.Response.ErrorCode;
import com.littleken.foodieCommon.Response.ServerResponse;
import com.littleken.foodiePojo.bo.ShopcartBO;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * Create by littleken on 2020/11/25 9:32
 */
@RestController
@RequestMapping("/shopCar")
public class ShopCarController {

    private static final Logger logger = LoggerFactory.getLogger(ShopCarController.class);

    @PostMapping("/add")
    public ServerResponse add(@RequestBody ShopcartBO shopcartBO,
                              HttpServletRequest request,
                              HttpServletResponse response) {
        if (StringUtils.isBlank(shopcartBO.getUserId())) {
            return ServerResponse.fail(ErrorCode.PARAMS_INVALID);
        }
        logger.error("添加购物车,{}", shopcartBO.toString());
        return ServerResponse.success();
    }

    @PostMapping("/delete/{userId}/{itemSpecId}")
    public ServerResponse delete(@PathVariable String userId,
                                 @PathVariable String itemSpecId,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        if (StringUtils.isBlank(userId) || StringUtils.isBlank(itemSpecId)) {
            return ServerResponse.fail(ErrorCode.PARAMS_INVALID);
        }
        logger.error("删除购物车,{},{}", userId,itemSpecId);
        return ServerResponse.success();
    }
}
